<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>商家结算管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <style>
        #guide_ul li{
            margin-top: 5px;
        }
    </style>
</head>
<body>
<div id="aaa"></div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">商家待结算订单</div> 
                <div class="layui-card-body">
                    <div class="layui-form-item layui-form">
                        <div class="layui-inline">
                            <label class="layui-form-label">订单编号</label>
                            <div class="layui-input-block">
                                <input type="text" name="order_sn_"  id="order_sn_"  placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div> 
						  <div class="layui-inline">
						  <label class="layui-form-label">支付时间</label>
						  <div class="layui-input-inline">
							<input type="text" class="layui-input" id="test6" placeholder="  ">
						  </div>
						</div>
                           <input name="" type="hidden" value="{$data.id}" id="object_id" >
						<input name="" type="hidden" value="{$data.type}" id="object_type"> 
                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="searchUserButton">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                         <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                    <button class="layui-btn" data-type="generateSettle">
                                       生成结算单
                                    </button>
                            </div>
                        </div>
                         <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" onclick="javascript:location.href='/admin/settlements/settlelist.html'">
                                     返回
                                </button>
                            </div>
                        </div>
                    </div>

                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate">
                    </table>
                  
                </div>
            </div>
        </div>
    </div>
</div>

<div id="contentShow" style="display:none;padding: 30px;">
    <p id="consultation"></p>
</div>  
<script src="/static/layuiadmin/layui/layui.js"></script>  
<script>
layui.use('laydate', function(){
  var laydate = layui.laydate;  
  //日期范围
  laydate.render({
    elem: '#test6'
    ,range: true
  }); 
});  

    var type=document.getElementById('object_type').value;
	var id=document.getElementById('object_id').value 
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate','set'], function(){
        $ = layui.jquery;
        var table = layui.table
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form; 
        table.render({ 
             elem: '#test-table-operate'
            ,id: 'queryList'
            ,url: "{:url('Settlements/orderlist')}?id="+id+"&type="+type 
            ,height: 'full-100'
            ,cols: [[ 
			     {type: 'checkbox',fixed: 'left'} 
                ,{field:'order_id',width:80,align:'center', title: 'ID'}
                ,{field:'shopName',align:'center',title: '店铺名称'}
                ,{field:'order_sn',align:'center',title: '订单编号'}
                ,{field:'pay_type',align:'center',title: '支付方式'} 
                ,{field:'order_price', align:'center', title: '商品金额'}
                ,{field:'order_price', align:'center', title: '订单总额'}
                ,{field:'commission_fee', align:'center', title: '佣金'}
                ,{field:'create_time', align:'center', title: '下单时间'}  
            ]]
            ,page:true
            ,limit:20 
			
        }); 
        form.render(null,'component-form-group');

        laydate.render({
            elem: '#search_time'
        });

        <!-- //监听工具条 -->
        <!-- table.on('tool(test-table-operate)', function(obj){ -->
            <!-- var data = obj.data; -->
            <!-- if(obj.event === 'showDetail'){ -->
                <!-- var loading = layer.load(1, { -->
                    <!-- shade: [0.1,'#fff'] //0.1透明度的白色背景 -->
                <!-- }); -->
                <!-- var order_id = data.order_id; -->

                <!-- $.ajax({ -->
                    <!-- url: "{:url('Order/hotelOrderDetail')}", -->
                    <!-- type: 'post', -->
                    <!-- dataType: 'json', -->
                    <!-- data: {order_id:order_id}, -->
                    <!-- success: function(data){ -->
                        <!-- layer.close(loading); -->
                        <!-- if (data.code === 0) { -->
                            <!-- if(data.data.food_store_tag==""){ -->
                                <!-- $('#hotel_name').html('未设置'); -->
                            <!-- }else{ -->
                                <!-- $('#hotel_name').html(data.data.hotel_name); -->
                            <!-- }    -->

                            <!-- var userDetailModal = layer.open({ -->
                                <!-- title:'导游订单详情' -->
                                <!-- ,type: 1 -->
                                <!-- ,shadeClose: true -->
                                <!-- ,area:['800px'] -->
                                <!-- ,content: $('#userDetail') -->
                            <!-- }); -->
                        <!-- }else{ -->
                            <!-- layer.msg('获取信息失败',{icon:2,time:1000}); -->
                        <!-- } -->


                    <!-- } -->
                <!-- }) -->
            <!-- }   else if(obj.event === 'food_del'){ -->
                <!-- layer.confirm('确认删除编号"' + data.order_sn + '"吗？', function(index){ -->
                    <!-- var loading = layer.load(1, { -->
                        <!-- shade: [0.1,'#fff'] //0.1透明度的白色背景 -->
                    <!-- }); -->
                    <!-- $.ajax({ -->
                        <!-- url: "{:url('Order/delGuide')}", -->
                        <!-- type: 'post', -->
                        <!-- dataType: 'json', -->
                        <!-- data: {id:data.order_id}, -->
                        <!-- success: function(msg){ -->
                            <!-- layer.close(loading); -->
                            <!-- if (msg.code == 0) { -->
                                <!-- obj.del(); -->
                                <!-- layer.msg(msg.msg,{icon:1,time:1000}); -->
                                <!-- layer.close(index); -->
                            <!-- }else{ -->
                                <!-- layer.msg(msg.msg,{icon:2,time:1000}); -->
                            <!-- } -->
                        <!-- } -->
                    <!-- }); -->
                <!-- }); -->
            <!-- } else if(obj.event === 'sendMerchant'){ -->
                <!-- var loading = layer.load(1, { -->
                    <!-- shade: [0.1,'#fff'] //0.1透明度的白色背景 -->
                <!-- }); -->
                <!-- var guide_id = data.guide_id; -->
                <!-- var guide_tel = data.guide_tel; -->
                <!-- var cardid = data.cardid; -->
                <!-- var rename = data.name; -->
                <!-- $.ajax({ -->
                    <!-- url: "{:url('Merchant/sendGuideMerchant')}", -->
                    <!-- type: 'post', -->
                    <!-- dataType: 'json', -->
                    <!-- data: {guide_id:guide_id,guide_tel:guide_tel,cardid:cardid,rename:rename}, -->
                    <!-- success: function(data){ -->

                    <!-- } -->
                <!-- }); -->
            <!-- }else if(obj.event === 'edit'){ -->
                <!-- window.location.href="{:url('order/editGuide')}?id=" + data.food_store_id; -->
            <!-- } -->

        <!-- }); -->

        var $ = layui.$, active = {
            addadmin: function() {
                window.location.href="{:url('Merchant/guideAdd')}";
            },
            searchUserButton:function(){

                var order_sn = $('#order_sn_').val();
                var create_time = $('#test6').val();  
                table.reload('queryList', {
                    where: {
                        order_sn:order_sn,
                        create_time: create_time 
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                //return false;
            },
            generateSettle:function(){ 







                var arr_box = [];
                var object_type = $("#object_type").val();
                var object_id = $("#object_id").val();
                var selectData = layui.table.checkStatus('queryList').data;
                var selectlength =selectData.length;
                if(selectlength<=0){
                    layer.msg("请选择要结算的订单");
                    return;
                }
                for(var i=0;i<selectlength;i++){
                     arr_box.push(selectData[i]['order_id']);
                } 
                var string = JSON.stringify(arr_box); 

               layer.confirm('共'+selectlength+'笔结算订单，请再次确认', {
                  btn: ['确认','取消'] //按钮
                }, function(){
                    $.ajax({
                url: "{:url('Settlements/generateSettle')}",
                type: 'post',
                dataType: 'json',
                data: {data:string,object_type:object_type,object_id:object_id},
                success: function(data){  
                    if (data.code === 0) { 
                        layer.msg(data.msg,{icon:2,time:1000});
                    }else if(data.code === 1){ 
                        layer.msg(data.msg,{icon:1,time:1000},function(){window.location.reload();});
                    }else { 
                        layer.msg('结算成功',{icon:2,time:1000});
                    }
                }
             }); 
                }, function(){ 
                    layer.close();
                }); 
            }

        };
        //绑定点击事件
        $('.test-table-operate-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>


</body>
</html>